package com.pitb.monitorcomplaints;

import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;

public class HttpPostUtil {
	public static final String MONITOR_COMPLAINT_URL = "http://securefy.com:8080/watsan/monitor_complaints.php?";

	public static String trackComplaint(String token) {
		try {
			StringBuilder stringBuilder = new StringBuilder();
			token = URLEncoder.encode(token, "utf-8");			
			String url = MONITOR_COMPLAINT_URL + "token=" + token ;
			HttpPost httppost = new HttpPost(url);
			HttpClient client = new DefaultHttpClient();
			HttpResponse response;
			stringBuilder = new StringBuilder();
			response = client.execute(httppost);
			HttpEntity entity = response.getEntity();
			InputStream stream = entity.getContent();
			int b;
			while ((b = stream.read()) != -1) {
				stringBuilder.append((char) b);
			}
			return stringBuilder.toString();
		} catch (ClientProtocolException e) {
		} catch (IOException e) {
		}
		return null;
	}
}
